package util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

import configs.Configuracao;

public class Arquivo {
	private FileReader fr;
	private BufferedReader br;
	private FileWriter fw;
	private String path;
	
	public Arquivo(String arquivo)
	{
		this.path = Configuracao.DIRETORIO + arquivo;
	}
	
	public void Escrita()
	{
		try {
			fw = new FileWriter( path, false );
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void Leitura()
	{
		try {
			fr = new FileReader( path );
			br = new BufferedReader( fr );
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void escrever(ArrayList<Double> dados, int intervalo)
	{
		try{
		for(int i = 0; i< dados.size(); i+=intervalo)
		{
			fw.write(String.valueOf(dados.get(i)).replace(".", ",")+"\n");
		}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void escrever(String texto)
	{
		try{
			fw.write(texto);
			}
			catch(Exception e){
				e.printStackTrace();
			}
	}
	
 	public void close()
	{
		try{
			if(fr != null) fr.close();
			if(br != null) br.close();
			if(fw != null) fw.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}
